package org.knot.autojmx.utils;

import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;

/**
 * spring工具类
 * 
 * @author  <a href="mailto:yuxiaoweimail@gmail.com">yuxiaowei</a>
 *
 */
public class SpringUtils {

	/**
	 * 获取被代理对象
	 * 
	 * @param bean proxy Bean
	 * @return target bean
	 * @throws Exception 
	 */
	public static Object getUserTarget(Object bean) throws Exception {
		if (AopUtils.isAopProxy(bean) && bean instanceof Advised) {
			Advised advised = (Advised) bean;
			bean = advised.getTargetSource().getTarget();
			return getUserTarget(bean);
		}
		return bean;
	}
}
